package org.dhu.user.controller;

import org.dhu.bean.Result;
import org.dhu.user.entity.dto.UserDto;
import org.dhu.user.entity.req.UserListReq;
import org.dhu.user.entity.req.UserReq;
import org.dhu.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;
@EnableSwagger2
@RestController
@RequestMapping("/user")
public class UserControllerr {
@Resource
private UserService userService;


    @PostMapping
    public Result add(@RequestBody UserReq userReq){
        UserDto userDto=new UserDto();
        BeanUtils.copyProperties(userReq,userDto);
        return  Result.ok(userService.addUser(userDto));
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        return  Result.ok(userService.delete(id));
    }


    @GetMapping
    public Result delete(UserListReq userListReq){
        UserDto userDto=new UserDto();
        BeanUtils.copyProperties(userListReq,userDto);
        return  Result.ok(userService.getUserPage(userDto));
    }


}
